TableElement = {

}



TableElement.backspace = function (self)
    if self.dataType == DataType.Number then
        NumberEditor.backspace(self)
    else
        TextEditor.backspace(self)
    end
end
TableElement.input = function (self, str)
    if self.dataType == DataType.Number then
        NumberEditor.input(self, str)
    else
        TextEditor.input(self, str)
    end
end

function TableElement:ctor()
    self:onClick(function ()
        FocusTextEditor = self
        -- self:emit(NodeEvent.OnTableElementClicked, self)
    end)
end

local elementCreatorDefault = function (self)
    local label = Node.Label():addTo(self)
    label.styleTarget = self
    label:addComponent(Align)
    self.label = label
end
local elementRendererDefault = function (self, data)
    self.label.string = data == nil and "nil" or tostring(data)
end

function TableElement:renderTableElement()
    local renderer = self._args.elementRenderer or elementRendererDefault
    renderer(self, self.tableElementData)
end
function TableElement:setUIData(data)
    self.tableElementData = data
    self:renderTableElement()
    if self._args.onSetData then
        self._args.onSetData(self, data)
    end
end
local function setTableElementSetting(self, args)
    local creator = args.elementCreator or elementCreatorDefault
    creator(self)
    if args.editable == false then
        self.interactable = false
    end
    self.dataType = args.dataType
    if args.style then
        self.style = args.style
    end
    if args.width then
        self.width = args.width
    end
    if args.fillLayout then
        self:addComponent(Stretch)
        self.stretchType = StretchType.Horizontal
        self.fillLayout = true
    end
    self._args = args
    return self
end

function Node.TableElement(args)
    local node = Node.new():addComponent(SwitchButton):addComponent(TableElement)
    node.interactable = false
    node.name = "TableElement"
    node.height = args.height or 30
    setTableElementSetting(node, args)
    return node
end